/*
 * Copyright 2021 ZLG
 * All rights reserved.
 *
 */

#ifndef MULTI_CYC_FIFO_H_
#define MULTI_CYC_FIFO_H_

#include "bsp.h"

/* Default open check input parameters */
#define SAFE_LEVEL_O3
#define DisableAllInterrupts()  __disable_irq()
#define EnableAllInterrupts()   __enable_irq()

/* Define error code */
typedef enum _muilt_cyc_fifo_error_code
{
    kMultiCycFiFo_Error_NONE = 0u,         /* No error */
    kMultiCycFiFo_Error_LEES_MIN,          /* Less than min */
    kMultiCycFiFo_Error_NO_NODE,
    kMultiCycFiFo_Error_OVER_MAX,          /* Over max */
    kMultiCycFiFo_Error_POINTER_NULL,      /* Pointer null */
    kMultiCycFiFo_Error_REGISTERED_SECOND, /* Timer registered */
    kMultiCycFiFo_Error_TIME_TYPE_ERRO,    /* Time type error */
    kMultiCycFiFo_Error_TIME_USEING,
    kMultiCycFiFo_Error_TIMEOUT,           /* Timeout*/
    kMultiCycFiFo_Error_WRITE_ERRO,
    kMultiCycFiFo_Error_READ_ERRO
} muilt_cyc_fifo_error_code_t;

typedef uint16_t fifo_id_t;
typedef uint16_t fifo_len_t;

#define FIFO_NUM (5u)           /* FIFO num */



#define TOTAL_FIFO_BYTES (2400u) /* Config total bytes */



#if defined(__cplusplus)
extern "C" {
#endif

/**********************************************************
**  Function Name       :   MCF_ApplyFifo
**  Description         :   Apply a FIFO
**  Input Parameter     :   fifoLen need apply FIFO len
                            fifoId FIFO ID. Use find this FIFO.
**  Modify Parameter    :   none
**  Output Parameter    :   p_applyStatus apply status. If apply success kMultiCycFiFo_Error_NONE, else kMultiCycFiFo_Error_XXX
**  Return Value        :   none
**  Version             :   v00.00.01
**  Author              :   Tomlin
**  Created Date        :   2013-3-27
**********************************************************/
void MCF_ApplyFifo(fifo_len_t fifoLen, fifo_len_t fifoId, muilt_cyc_fifo_error_code_t *p_applyStatus);

/**********************************************************
**  Function Name       :   MCF_WriteDataInFifo
**  Description         :   write data in FIFO.
**  Input Parameter     :   fifoId FIFO ID
                            p_writeDataBuffer Need write data buffer
                            writeDatalen  write data len
**  Modify Parameter    :   none
**  Output Parameter    :   p_writeStatus write data status. If successful kMultiCycFiFo_Error_NONE, else kMultiCycFiFo_Error_XX
**  Return Value        :   none
**  Version             :   v00.00.01
**  Author              :   Tomlin
**  Created Date        :   2013-3-27
**********************************************************/
void MCF_WriteDataInFifo(fifo_id_t fifoId,
                         uint8_t *p_writeDataBuffer,
                         fifo_len_t writeDatalen,
                         muilt_cyc_fifo_error_code_t *p_writeStatus);

/**********************************************************
**  Function Name       :   MCF_ReadDataFromFifo
**  Description         :   Read data from FIFO.
**  Input Parameter     :   fifoId need read FIFO
                            needReadDataLen read data len
**  Modify Parameter    :   none
**  Output Parameter    :   p_readDataBuf need read data buffer.
                            p_actualReadDataLen need read data len
                            readStatus read status. If read successful kMultiCycFiFo_Error_NONE, else kMultiCycFiFo_Error_XXX
**  Return Value        :   none
**  Version             :   v00.00.01
**  Author              :   Tomlin
**  Created Date        :   2013-3-27
**********************************************************/
void MCF_ReadDataFromFifo(fifo_id_t fifoId, fifo_len_t needReadDataLen,
                          uint8_t *p_readDataBuf,
                          fifo_len_t *p_actualReadDataLen,
                          muilt_cyc_fifo_error_code_t *readStatus);

/**********************************************************
**  Function Name       :   MCF_GetCanReadLen
**  Description         :   Get FIFO have data.
**  Input Parameter     :   fifoId FIFO ID
**  Modify Parameter    :   none
**  Output Parameter    :   p_canReadLen how much data can read.
                            p_getStatus get status. If get successful kMultiCycFiFo_Error_NONE, else kMultiCycFiFo_Error_XXX
**  Return Value        :   none
**  Version             :   v00.00.01
**  Author              :   Tomlin
**  Created Date        :   2013-3-27
**********************************************************/
void MCF_GetCanReadLen(fifo_id_t fifoId, fifo_len_t *p_canReadLen, muilt_cyc_fifo_error_code_t *p_getStatus);

/**********************************************************
**  Function Name       :   MCF_GetCanWriteLen
**  Description         :   Get can write data.
**  Input Parameter     :   fifoId FIFO ID
**  Modify Parameter    :   none
**  Output Parameter    :   p_canWriteLen how much data can write.
                            p_getStatus get data status. If get successful kMultiCycFiFo_Error_NONE, else kMultiCycFiFo_Error_XX
**  Return Value        :   none
**  Version             :   v00.00.01
**  Author              :   Tomlin
**  Created Date        :   2013-3-27
**********************************************************/
void MCF_GetCanWriteLen(fifo_id_t fifoId, fifo_len_t *p_canWriteLen, muilt_cyc_fifo_error_code_t *p_getStatus);

/**********************************************************
**  Function Name       :   MCF_ClearFIFO
**  Description         :   Clear FIFO, set read pointer equal write pointer
**  Input Parameter     :   fifoId FIFO ID
**  Modify Parameter    :   none
**  Output Parameter    :   p_getStatus get data status. If get successful kMultiCycFiFo_Error_NONE, else kMultiCycFiFo_Error_XX
**  Return Value        :   none
**  Version             :   v00.00.01
**  Author              :   Tomlin
**  Created Date        :   2019-6-18
**********************************************************/
void MCF_ClearFIFO(fifo_id_t fifoId, muilt_cyc_fifo_error_code_t *p_getStatus);

#if defined(__cplusplus)
}
#endif

#endif /* MULTI_CYC_FIFO_H_ */

/* -------------------------------------------- END OF FILE -------------------------------------------- */
